<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink">
 <xsl:output method="xml" indent="yes"/>
 <xsl:key name="comps" match="Competence" use="Type" />
 <xsl:template match="/">
  <fo:root>
   <fo:layout-master-set>
    <fo:simple-page-master master-name="A4" page-height="297mm" page-width="210mm" margin-top="10mm"  margin-bottom="0mm"  margin-left="20mm" margin-right="20mm">
          <fo:region-body margin-top="20mm" margin-bottom="20mm" margin-left="0mm" margin-right="0mm"/>
          <fo:region-before	region-name="xsl-region-before" extent="10mm"/>
          <fo:region-after region-name="xsl-region-after" extent="10mm"/>
    </fo:simple-page-master>
   </fo:layout-master-set>

   <fo:page-sequence master-reference="A4">
    <fo:static-content flow-name="xsl-region-before">
      <fo:block font-family="Helvetica" font-size="10pt"
          text-align="center">
          <fo:inline>Liste des compétences</fo:inline>
      </fo:block>
    </fo:static-content>

    <fo:static-content flow-name="xsl-region-after">
      <fo:block font-family="Helvetica" font-size="10pt" text-align="center">
          Page - <fo:page-number />
      </fo:block>
    </fo:static-content>
    
    <fo:flow flow-name="xsl-region-body">
      <fo:block background-color="darkblue" space-after="6mm">
        <fo:inline font-size="30pt" color="white">Compétences</fo:inline>
      </fo:block>
      <fo:block>
       <xsl:apply-templates select="Competences"/>
      </fo:block>
    </fo:flow>
    
   </fo:page-sequence>
  </fo:root>
 </xsl:template>

 <xsl:template match="Competences">
   <xsl:for-each select="Competence[count(. | key('comps', Type)[1]) = 1]">
      <xsl:sort select="Type" />
      <fo:block background-color="#3366FF" space-after="3mm">
        <fo:inline font-size="20pt" color="white"><xsl:value-of select="Type" /></fo:inline>
      </fo:block>
      <xsl:variable name="compType" select="Type"></xsl:variable>
           
      <xsl:for-each select="//Competence[Type = $compType]">
        <xsl:sort select="Nom" />
        <fo:block>
          - <fo:inline font-size="12pt"><xsl:value-of select="Nom" /></fo:inline>
        </fo:block>
      </xsl:for-each>
      
      <fo:block break-after="page"/>
    </xsl:for-each>
  </xsl:template>
 
</xsl:stylesheet>

